package com.example.spring_gobang.game;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class OnlineUserManage {
    //用来处理在游戏大厅页面用户的在线管理状态
    private ConcurrentHashMap<Integer, WebSocketSession> gameHall = new ConcurrentHashMap<>();
    //用来处理游戏房间页面用户的在线管理状态
    private ConcurrentHashMap<Integer,WebSocketSession> gameRoom = new ConcurrentHashMap<>();
    public void enterGameHall(Integer userId,WebSocketSession session){
        gameHall.put(userId,session);
    }
    public void exitGameHall(Integer userId){
        gameHall.remove(userId);
    }
    public WebSocketSession getFromById(Integer userId){
        return gameHall.get(userId);
    }
    public void enterGameRoom(Integer userId,WebSocketSession session){
        gameRoom.put(userId,session);
    }
    public void exitGameRoom(Integer userId){
        gameRoom.remove(userId);
    }
    public WebSocketSession getRoomById(Integer userId){
       return gameRoom.get(userId);
    }
}
